import { pageCustomForm } from '@/api/workflow/customForm'

export const flowableMixin = {
  components: {},
  data() {
    return {
      customformList: [],
      formQueryParams: {
        pageNum: 1,
        pageSize: 1000
      }
    }
  },
  created() {
    this.ListCustomForForm()
  },
  computed: {
    /**
     * 所有的流程表单，组件化注册，无需维护，从后端获取
     * @returns {*[]}
     */
    allFormComponent: function() {
      return this.customformList
    }
  },
  methods: {
    /**
     * 挂载自定义业务表单列表
     * @returns {Promise<void>}
     * @constructor
     */
    async ListCustomForForm() {
      let that = this
      pageCustomForm(this.formQueryParams).then(res => {
        let cfList = res.rows
        cfList.forEach((item, index) => {
          let cms = {
            text: item.flowName,
            routeName: item.routeName,
            component: (resolve) => require([`@/views/${item.routeName}.vue`], resolve),
          }
          that.customformList.push(cms)
        })
      })
    },
    /**
     * 查找自定义表单组件
     * @param routeName
     * @returns {{}}
     */
    getFormComponent(routeName) {
      return _.find(this.allFormComponent, { routeName: routeName }) || {}
    },
  }

}
